import { useEffect } from "react";
import { useReactive } from "ahooks";

export default function messageModal() {
	const state = useReactive({
		messageInfo: {},
		messageUuid: window.messageUuid,
		actionParams: window.messageActionParams,
	});

	const getMessageActionParams = async (e, params) => {
		if (params) state.actionParams = params;
	};

	const setMessageInfo = (messageInfo) => (state.messageInfo = messageInfo);

	useEffect(() => {
		electron.ipcRenderer.on("inject-ipc-data", getMessageActionParams);
		return () => electron.ipcRenderer.removeListener("inject-ipc-data", getMessageActionParams);
	}, []);

	return {
		...state,
		setMessageInfo,
	};
}
